macro_rules! events {
    (
        keyboard: { $( $k_alias:ident : $k_sdl:ident ),* }
    )
    => {
        use sdl2::EventPump;
        pub struct ImmediateEvents {
            $(pub $k_alias: Option<bool>,)*
        }

        impl ImmediateEvents {
            pub fn new() -> ImmediateEvents {
                ImmediateEvents {
                    $($k_alias: None,)*
                }
            }
        }

        pub struct Events {
            pump: EventPump,
            pub now: ImmediateEvents,
            pub quit: bool,
            $(pub $k_alias: bool,)*
        }

        impl Events {
            pub fn new(pump: EventPump) -> Events {
                Events {
                    pump: pump,
                    now: ImmediateEvents::new(),
                    quit: false,
                    $($k_alias: false,)*
                }
            }

            pub fn pump(&mut self) {
                self.now = ImmediateEvents::new();//这句话很重要
                for event in self.pump.poll_iter() {
                    use sdl2::event::Event::*;
                    use sdl2::keyboard::Keycode::*;
                    match event {
                        Quit { .. } => self.quit = true,
                        KeyDown { keycode, .. } => match keycode {
                            $(Some($k_sdl) => {
                                if !self.$k_alias {
                                    self.now.$k_alias = Some(true)
                                }
                                self.$k_alias = true
                            })*
                            _ => {}
                        },
                        KeyUp { keycode, .. } => match keycode {
                            $(Some($k_sdl) => {
                                self.now.$k_alias = Some(false);
                                self.$k_alias = false
                            })*
                            _ => {}
                        },
                        _ => {}
                    }
                }
            }
        }
    }
}